import routes from 'server/route/index';
import utils from 'server/core/utils';
import playerStorage from 'js/core/playerStorage';
import eventHandle from 'server/handle/eventHandle';
import playerHandle from 'server/handle/playerHandle';
import MazeModel from 'server/model/mazeModel';
import ExamineHandle from 'server/handle/examineHandle';
import battleHandle from 'server/handle/battleHandle';
import packageHandle from 'server/handle/packageHandle';
import monsterHandle from 'server/handle/monsterHandle';

import {
    totalConfig,
    propName
} from 'server/config/templateConfig.js';
let cardsConfig = totalConfig.card;
let itemsConfig = totalConfig.item;

routes.setLogin('addGold', null, (player, msg, cb) => {
    player.basicInfo.gold += 10000;
    cb(0);
});

routes.setLogin('lvlup', null, (player, msg, cb) => {
    player.basicInfo.lvl += 1;
    cb(0);
});


//获取怪物属性
routes.setLogin('getMonsterFightAttri', [
    ['monsterId', 'number'],
    ['monsterType', 'number'],
    ['lvl', 'number'],
], (player, msg, cb) => {
    let monster = monsterHandle.createMonster(msg.monsterId, msg.monsterType, msg.lvl);
    cb(0, {
        monster: monster
    })
});

routes.setLogin('addItem', [
    ['itemId', 'number']
], (player, msg, cb) => {
    let itemId = msg.itemId;
    if (!itemsConfig[itemId]) {
        cb(1);
        return;
    }

    if (packageHandle.isHasEmpty(player.bag, 1) === -1) {
        cb(2);
        return;
    }


    packageHandle.addItem(player.bag, itemId, 1);
    console.log(player.bag)
    cb(0)
});

//全体生命恢复
routes.setLogin('cureAll', null, (player, msg, cb) => {
    player.battleTeams.forEach(element => {
        element.fightAttri.hp = element.fightAttri.maxHp;
    });
    cb(0);
});

//重新计算属性
routes.setLogin('calcAttri', null, (player, msg, cb) => {
    playerHandle.calcPlayer(player);
    cb(0);
});